﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MODEL;
using System.Data;
using UsersDAL;
using System.Data.SqlClient;

namespace DAL
{
    public class FriendsDAL
    {
        private Friends ToFriends(DataRow row)
        {
            Friends model = new Friends();
            model.Id = (System.Int32)sqlHelper.GetToDbvalue(row["Id"]);
            model.HostId = (System.Int64)sqlHelper.GetToDbvalue(row["HostId"]);
            model.FriendId = (System.Int64)sqlHelper.GetToDbvalue(row["FriendId"]);
            return model;
        }
        public Friends[] GetAll()
        {
            DataTable table = sqlHelper.ExecuteDataTable("select *from Friends");
            Friends[] models = new Friends[table.Rows.Count];
            for (int i = 0; i < table.Rows.Count; i++)
            {
                DataRow row = table.Rows[i];
                models[i] = ToFriends(row);
            }
            return models;
        }
        public void Insert(long HostId, long FriendId)
        {
            sqlHelper.ExecuteNonQuery("insert into Friends(HostId,FriendId)values(@HostId,@FriendId)"
            , new SqlParameter("@HostId", HostId)
            , new SqlParameter("@FriendId", FriendId)
            );
        }
    }
}
